package cn.iocoder.yudao.module.pi.dal.mysql.exec;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pi.controller.admin.pipline.exec.vo.ExecPageReqVO;
import cn.iocoder.yudao.module.pi.dal.dataobject.exec.ExecDO;
import cn.iocoder.yudao.module.pi.dal.dataobject.task.TaskDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 部署执行 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ExecMapper extends BaseMapperX<ExecDO> {

    default PageResult<ExecDO> selectPage(ExecPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ExecDO>()
                .eqIfPresent(ExecDO::getDeployId, reqVO.getDeployId())
                .eqIfPresent(ExecDO::getEnv, reqVO.getEnv())
                .eqIfPresent(ExecDO::getRegion, reqVO.getRegion())
                .eqIfPresent(ExecDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(ExecDO::getPiplineId, reqVO.getPiplineId())
                .eqIfPresent(ExecDO::getPiplineRunId, reqVO.getPiplineRunId())
                .betweenIfPresent(ExecDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ExecDO::getId));
    }

    default List<ExecDO> getExecBatchTag(ExecDO exec){
        return selectList(new LambdaQueryWrapperX<ExecDO>()
                .eqIfPresent(ExecDO::getBatchId, exec.getBatchId())
                .eqIfPresent(ExecDO::getTag, exec.getTag())
                .orderByAsc(ExecDO::getId));
    }
}